package com.qfedu.meidijiaju.service.impl;

import com.qfedu.meidijiaju.common.ResponseData;
import com.qfedu.meidijiaju.entity.ShipuYxy;
import com.qfedu.meidijiaju.mapper.ShipuYxyMapper;
import com.qfedu.meidijiaju.service.ShipuYxyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 食谱 服务实现类
 * </p>
 *
 * @author meidimeiju
 * @since 2022-10-05
 */
@Service
public class ShipuYxyServiceImpl extends ServiceImpl<ShipuYxyMapper, ShipuYxy> implements ShipuYxyService {

    @Autowired
    private ShipuYxyMapper shipuYxyMapper;

    @Override
    public ResponseData<List<ShipuYxy>> findShiPuByLike(String caipinName) {

        ResponseData<List<ShipuYxy>> responseData = new ResponseData<>();

        if (!StringUtils.isEmpty(caipinName)){

            List<ShipuYxy> shipuYxyList = shipuYxyMapper.findShiPuByLike("%"+caipinName+"%");

            if (shipuYxyList != null && shipuYxyList.size() > 0){

                responseData.setCode(200);

                responseData.setData(shipuYxyList);

            } else {

                responseData.setCode(400);

                responseData.setMsg("没有找到关于"+caipinName+"的食谱");

            }
        } else {

            responseData.setCode(400);

            responseData.setMsg("请输入信息！");

        }

        return responseData;
    }

    @Override
    public ResponseData<ShipuYxy> findShiPuById(int caipinId) {

        ResponseData<ShipuYxy> responseData = new ResponseData<>();

        ShipuYxy shipuYxy = shipuYxyMapper.findShiPuById(caipinId);

        if (shipuYxy != null){

            responseData.setCode(200);

            responseData.setData(shipuYxy);
        } else {

            responseData.setCode(400);

            responseData.setMsg("无数据！");
        }

        return responseData;
    }
}
